package com.xyy.saas.payment.manage.cores.vo;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author zhangwenxiong
 * @Date 2020/10/22 16:25
 */
@Data
public class ResultPageVo<T> implements Serializable {
    private static final long serialVersionUID = -7716848940472375888L;
    public static int success_code = 0;
    public static int fail_code = 1;

    /**
     * 总数
     */
    private long totalCount;

    /**
     * 每页数
     */
    private int pageSize;

    /**
     * 当前页
     */
    private int page;

    /**
     * 总页数
     */
    private int totalPage;

    /**
     * 状态码
     */
    private int code;

    /**
     * 消息
     */
    private String msg;
    private T data;

    public static <T> ResultPageVo<T> createSuccess() {
        ResultPageVo resultVo = new ResultPageVo();
        resultVo.setCode(success_code);
        resultVo.setMsg("success");
        return resultVo;
    }

    public static <T> ResultPageVo<T> createSuccess(int page,int pageSize,long totalCount,T param) {
        ResultPageVo resultVo = new ResultPageVo();
        resultVo.setCode(success_code);
        resultVo.setMsg("success");
        resultVo.setPage(page);
        resultVo.setPageSize(pageSize);
        resultVo.setTotalCount(totalCount);
        resultVo.setData(param);
        resultVo.setTotalPage((int) (totalCount%pageSize == 0?totalCount/pageSize:(totalCount/pageSize)+1));
        return resultVo;
    }

    public static <T> ResultPageVo<T> createFail(String msg) {
        ResultPageVo resultVo = new ResultPageVo();
        resultVo.setCode(fail_code);
        resultVo.setMsg(msg);
        return resultVo;
    }

    public void setFail(String msg) {
        this.setCode(fail_code);
        this.setMsg(msg);
    }
}
